import 'dart:async';
import 'package:todo_app/constants/Screen.dart';
import 'package:flutter/material.dart';

import './OverlaySupport.dart';

enum OverlayToastPosition {
  TOP,
  CENTER,
  BOTTOM
}

enum OverlayToastDelay {
  LONG,
  SHORT,
}

void showOverlayToast(
  String msg,
  {
    OverlayToastPosition? position,
    OverlayToastDelay? delay,
    double? fontSize,
    Color? backgroundColor,
    Color? textColor
  }
) async {
  OverlayEntry entry = showOverlay(
    builder: (BuildContext _, OverlaySupportState state) {
      var _backgroundColor = backgroundColor ?? Colors.black.withOpacity(0.6);
      var _color = textColor ?? Colors.white;
      var _fontSize = fontSize ?? Screen.sizeByDesign(14);
      Alignment alignment = Alignment.center;
      double top = 0;
      double bottom = 0;
      if(position == OverlayToastPosition.TOP) {
        alignment = Alignment.topCenter;
        top = 100;
      }
      if(position == OverlayToastPosition.BOTTOM) {
        alignment = Alignment.bottomCenter;
        bottom = 100;
      }
      return Container(
        width: Screen.width,
        alignment: alignment,
        margin: EdgeInsets.only(
          top: top,
          bottom: bottom
        ),
        child: Container(
          padding: EdgeInsets.symmetric(
            horizontal: Screen.sizeByDesign(16),
            vertical: Screen.sizeByDesign(6)
          ),
          margin: EdgeInsets.symmetric(horizontal: Screen.sizeByDesign(16)),
          decoration: BoxDecoration(
            color: _backgroundColor,
            borderRadius: BorderRadius.circular(Screen.sizeByDesign(8)),
          ),
          child: Text(
            msg,
            style: TextStyle(
              color: _color,
              fontSize: _fontSize,
              decoration: TextDecoration.none,
              fontWeight: FontWeight.normal
            ),
          ),
        )
      );
    }
  );
  Duration duration = delay == OverlayToastDelay.LONG ? Duration(seconds: 3) : Duration(seconds: 2);
  await Future.delayed(duration);
  entry.remove();
}
